/***************************************************************************
 *   Copyright (C) 2007 by Alexandre Masselot,,,   *
 *   alex@alex-laptop   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef BOLSCORINGMODELDANCIK_H
#define BOLSCORINGMODELDANCIK_H

#include <spectraalignmentscoringmodel.h>
#include <peaktheomsms.h>
#include <peaktheomsmsfactory.h>


namespace bol {

/**
	@author Alexandre Masselot,GeneBio,http://www.genebio.com, <alexandre.masselot@gmail.com>
*/
class ScoringModelDancik : public SpectraAlignmentScoringModel<PeakTheoMsms, PeakIntensity>
{
  /**
   * Those vector are taken to count the number of matches, then the weight for scoring.
   * 
   * The index of the vector is the index assocaited to the series by PeakTheoMsMsFactory.
   */
  vector<int> v_learn_altCpt, v_learn_altNb, v_learn_nullCpt, v_learn_nullNb;
  vector<double> v_prob_match, v_prob_nomatch;
  vector<double> v_score_match, v_score_nomatch;
  vector<double> v_bitInfo; 
   //the series taken into account
  vector<unsigned int>m_series;
  //i'th set to true is the series number i is in the list
  vector<bool>m_seriesFlag;

  void learn_push(const SpectraAlignment<PeakTheoMsms,PeakIntensity>& spalign,
                  vector<int>&cpt, vector<int>&Nb
                 );


  /**
   * for an alignement, count how many positions where covered for a given series (mixing y and y++ per exemple, as well as how many were putative)
   * @param spalign 
   * @param nbtot an array (index is the frag series) to count how many sites were possible for the alignement
   * @param nbmatch  idem to count how many fragment were matched (ocunting once if the same frgment is matched b and b++)
   */
  void coverage(const SpectraAlignment<PeakTheoMsms,PeakIntensity>& spalign, unsigned int *nbpot, unsigned int *nbmatch);
  public:
    ScoringModelDancik();

    ~ScoringModelDancik();

    void series_add(const string);

    void init();

    double score(const SpectraAlignment<PeakTheoMsms,PeakIntensity>& spalign);
    void learn_init();
    
    void learn_pushAlternate(const SpectraAlignment<PeakTheoMsms,PeakIntensity>& spalign);
    void learn_pushNull(const SpectraAlignment<PeakTheoMsms,PeakIntensity>& spalign);
    void learn_finalize();

    void setScoreValues(const string series, const double bit, const double score_match, const double score_nomatch);
    void getScoreValues(const string& series, double* bit = NULL, double* score_match = NULL, double* score_nomatch = NULL);
    friend ostream& operator<<(ostream& out, const ScoringModelDancik& model);

};

}

#endif
